package com.tgy.leetcode;

import java.util.Stack;

/**
 * @Author: tgy
 * @Date: 12/27/20 1:34 PM
 *
 * https://leetcode-cn.com/problems/largest-rectangle-in-histogram/
 *
 */
public class _84_柱状图中最大的矩形_01 {

    public int largestRectangleArea(int[] heights) {

        if (heights == null || heights.length == 0) {

            return 0;
        }

        int max = 0;

        int[] leftToRight = new int[heights.length];
        int[] rightToLeft = new int[heights.length];

//        for (int i = 0; i < leftToRight.length; i++) {
//            leftToRight[i] = -1;
//        }

        leftToRight[0] = 1;
        for (int i = 1; i < leftToRight.length; i++) {

            if (heights[i - 1] < heights[i]) {

                leftToRight[i] = 1;
            }else if (heights[i - 1] == heights[i]){

                leftToRight[i] = leftToRight[i - 1] + 1;
            }else {

                int leftLen  = leftToRight[i - 1];

                int leftIndex = i - 1;
//                i- 1 - leftLen + 1;
                while (leftLen > 0 && heights[leftIndex - leftIndex + 1] > heights[i]) {


                }

//                while (min >= 0 && heights[min] > heights[i]) {
//
//                    min = leftToRight[min];
//                }
//
//                if (min >= 0) {
//
//                    leftToRight[i] = min;
//                }
            }
        }





        return max;
    }
}
